<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property int $goods_id
 * @property int $total_num
 * @property int $use_num
 * @property int $leave_num
 * @property int $bad_num
 * @property int $warn_num
 * @property string $updated_at
 * @property string $created_at
 */
class GoodsStock extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'goods_stock';

    /**
     * @var array
     */
    protected $fillable = ['goods_id', 'total_num', 'use_num', 'leave_num', 'warn_num','updated_at','created_at'];

    /**
     * 每日库存更新---进货
     * @param $num
     * @param $goods_stock
     * @return mixed
     */
    public static function goods_add($num,$goods_stock)
    {
        $goods_stock->total_num +=$num;
        $goods_stock->leave_num +=$num;
        $goods_stock->updated_at = date("Y-m-d H:i:s");
        return $goods_stock->save();
    }

    /**
     * 每日库存更新---领用
     * @param $num
     * @param $goods_stock
     * @return mixed
     */
    public static function goods_use($num,$goods_stock)
    {
        $goods_stock->use_num +=$num;
        $goods_stock->leave_num -=$num;
        $goods_stock->updated_at = date("Y-m-d H:i:s");
        return $goods_stock->save();
    }

    /**
     * 每日库存更新---报损
     * @param $num
     * @param $goods_stock
     * @return mixed
     */
    public static function goods_bad($num,$goods_stock)
    {
        $goods_stock->bad_num +=$num;
        $goods_stock->leave_num -=$num;
        $goods_stock->updated_at = date("Y-m-d H:i:s");
        return $goods_stock->save();
    }

}
